import 'dart:math';
import 'package:flutter/material.dart';

class RandomContrastingColorsUtil {
  static Color generateRandomColor() {
    Random random = Random();
    return Color.fromRGBO(
      random.nextInt(256),
      random.nextInt(256),
      random.nextInt(256),
      1.0,
    );
  }

  static List<Color> generateHighContrastColors() {
    Color color1;
    Color color2;
    do {
      color1 = generateRandomColor();
      color2 = generateRandomColor();
    } while (!isHighlyContrasting(color1, color2));
    return [color1, color2];
  }

  static bool isHighlyContrasting(Color color1, Color color2) {
    double brightness1 = calculateBrightness(color1);
    double brightness2 = calculateBrightness(color2);
    return brightness1 < 128 && brightness2 > 128 || brightness1 > 128 && brightness2 < 128;
  }

  static double calculateBrightness(Color color) {
    return (color.red * 299 + color.green * 587 + color.blue * 114) / 1000;
  }
}